<?php
namespace Admin\Controller;

use Think\Controller;

class UploadController extends Controller
{
    public function uploader(){
        $upload=$this->upload();
        //dd($upload);
        echo json_encode($upload);//返回在页面做一个隐藏域，把地址填进去

    }

    public function upload(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =     ''; // 设置附件上传（子）目录
        // 上传文件
        $info   =   $upload->upload();
//        dd($info['Filedata']);die;
        $Filedata=current($info);
        if(!$info) {// 上传错误提示错误信息，message按照后盾要上传类要求的格式返回，才能被js接受
            return ['valid'=>0,'message'=>$upload->getError()];
        }else{// 上传成功
            return ['valid'=>1,'message'=>'Uploads/'.$Filedata['savepath'].$Filedata['savename']];

        }
    }
}